// Copyright 2014 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

{namespace e2e.ext.ui.templates.dialogs.importconfirmation autoescape="strict"}

/**
 * Renders the text for key import confirmation dialog.
 * @param promptImportKeyConfirmLabel A sentence asking the user to confirm
 *     the key import.
 * @param selectAllLabel The label for the "select all" link.
 * @param keys Array of keys (e2e.openpgp.Keys).
 * @param secretKeyDescription Text describing a secret key.
 * @param publicKeyDescription Text describing a public key.
 * @param secretSubKeyDescription Text describing a secret subkey.
 * @param publicSubKeyDescription Text describing a public subkey.
 */
{template .importKeyConfirm}
  <p>{$promptImportKeyConfirmLabel} (
    <a class="{e2e.ext.constants.CssClass.SELECT_ALL_LINK}">{$selectAllLabel}</a>)
  </p>
  <div>
    {foreach $key in $keys}
      <div class="{e2e.ext.constants.CssClass.KEY_META}">
        <p>
          <strong>
            {foreach $uid in $key.uids}
              {$uid}
              {if not isLast($uid)}, {/if}
            {/foreach}
          </strong>:
        </p>
        {let $keyId kind="text"}key-{index($key)}{/let}
        <br><input id="{$keyId}" type="checkbox" data-mainkey="{index($key)}">
        <label for="{$keyId}">
          {call .keyPacketInfo}
            {param keyPacketInfo: $key.key /}
            {param secretKeyDescription: $secretKeyDescription /}
            {param publicKeyDescription: $publicKeyDescription /}
          {/call}
        </label>
        {foreach $subKeyInfo in $key.subKeys}
          {let $subKeyId kind="text"}{$keyId}-sub-{index($subKeyInfo)}{/let}
          <br><input id="{$subKeyId}" type="checkbox"
                     data-mainkey="{index($key)}" data-subkey="yes"
                     class="{e2e.ext.constants.CssClass.KEY_SUBKEY}">
          <label for="{$subKeyId}">
            {call .keyPacketInfo}
              {param keyPacketInfo: $subKeyInfo /}
              {param secretKeyDescription: $secretSubKeyDescription /}
              {param publicKeyDescription: $publicSubKeyDescription /}
            {/call}
          </label>
        {/foreach}
      </div>
    {/foreach}
  </div>
{/template}


/**
 * Renders information about a single key packet.
 * @param keyPacketInfo Single packet key info (e2e.openpgp.KeyPacketInfo).
 * @param secretKeyDescription Text to display if the key is secret.
 * @param publicKeyDescription Text to display if the key is public.
 */
{template .keyPacketInfo}
  <div>
    <span class="{e2e.ext.constants.CssClass.KEY_TYPE_DESC}">
      {if $keyPacketInfo.secret}
        {$secretKeyDescription}
      {else}
        {$publicKeyDescription}
      {/if}
      {sp}{$keyPacketInfo.algorithm}
    </span>
    {sp}
    <span class="{e2e.ext.constants.CssClass.KEY_FINGERPRINT}">
      {$keyPacketInfo.fingerprintHex}
    </span>
  </div>
{/template}
